<?php

class Quad_Orm_Metadata {
	
	public $db;
	
	public function __construct($db) {
		$this->db = $db;
	}
	
	public function getTableNames() {
		$tables = $this->db->listTables();
		return $tables;
	}
	
	public function getTableMetadata($table) {
		$fieldList = $this->db->describeTable($table);		
		$cols = array();
		$serial = false;
		foreach ($fieldList as $field) {
			$col = $field['COLUMN_NAME'];
			$cols[] = $col;
			if ($field['PRIMARY']) {
				$pks[] = $col;
			}
			if ($field['IDENTITY']) {
				$serial = $col;
			}
		}
		$metadata = array(
			'columns'=>$cols,
			'pk'=>$pks,
			'serial'=>$serial
		);
		return $metadata;
	}
	
}
